package double_pointer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-11-30
 * Time: 17:40
 */
public class HappyNumber {
    private static int bitSum(int n) {
        int sum = 0;
        while(n != 0) {
            int m = n % 10;
            sum += m * m;
            n /= 10;
        }
        return sum;
    }
    public static boolean isHappy(int n) {
        int low = n;
        int fast = n;
        do {
            low = bitSum(low);
            for (int i = 0; i < 2; i++) {
                fast = bitSum(fast);
            }
        }while (low != fast);
        return low == 1;
    }
    public static void main(String[] args) {
        System.out.println(isHappy(19));
    }
}
